package informationGet.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.android.volley.VolleyError;
import com.whu.zj.R;
import com.whu.zj.UIHandler;

import java.util.ArrayList;
import java.util.List;

import gis.activity.MapShow;
import informationGet.adapter.ShowPointsAdapter;
import informationGet.dto.Points;
import informationGet.network.GetInfoPoints;
import inter.Delegate;

/**
 * 记录的历史信息查看
 * Created by Administrator on 2016/3/14.
 */
public class ReadInfoActivity extends UIHandler.BaseActivity {


    ListView lv_points;
    List<Points> pointsList = new ArrayList<Points>();
    ShowPointsAdapter showPointsAdapter = new ShowPointsAdapter();
    {
        showPointsAdapter.setPointsList(pointsList);
    }



    Delegate points = new Delegate() {
        @Override
        public void onResponse(String response) {
            if (!response.startsWith("["))return;
            List<Points> pointsesTmp = JSON.parseArray(response,Points.class);
            pointsList.clear();
            pointsList.addAll(pointsesTmp);
            showPointsAdapter.notifyDataSetChanged();
        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    };

    GetInfoPoints getInfoPoints = new GetInfoPoints();
    {
        getInfoPoints.setDelegate(points);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_readinfo);

        initview();
        initdata();
    }

    private void initdata() {
        getInfoPoints.get();
    }

    // 初始化界面
    private void initview() {

        lv_points = (ListView) findViewById(R.id.id_lv_points);
        lv_points.setAdapter(showPointsAdapter);
        lv_points.setDividerHeight((int)getResources().getDimension(R.dimen.x4));
        lv_points.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Points points = (Points) view.getTag(R.id.id_points);
//                Intent intent = new Intent(ReadInfoActivity.this,MapShow.class);
//                intent.putExtra("points",points);
//                ReadInfoActivity.this.startActivity(intent);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(getInfoPoints != null)
            getInfoPoints.cancel();
    }
}
